package com.streamhub.client;

import com.google.gwt.core.client.JavaScriptObject;

class StreamHubGWTBridge implements StreamHubBridge {
	public native void createStreamHub() /*-{
		$wnd.gwtStreamHub = new $wnd.StreamHub();
	}-*/;

	public native void exportStaticOnUpdateMethod() /*-{
		$wnd.gwtStreamHubUpdate = @com.streamhub.client.StreamHubGWTAdapter::onUpdate(Ljava/lang/String;Lcom/google/gwt/core/client/JavaScriptObject;);
	}-*/;

	public native void connectHub(String url) /*-{
		$wnd.gwtStreamHub.connect(url);
	}-*/;
	
	public native void connectHub(JavaScriptObject config) /*-{
		$wnd.gwtStreamHub.connect(config);
	}-*/;

	public native void disconnectHub() /*-{
		$wnd.gwtStreamHub.disconnect();
	}-*/;

	public native void subscribe(String topic) /*-{
		$wnd.gwtStreamHub.subscribe(topic, $wnd.gwtStreamHubUpdate);
	}-*/;

	public native void subscribe(JavaScriptObject topics) /*-{
		$wnd.gwtStreamHub.subscribe(topics, $wnd.gwtStreamHubUpdate);
	}-*/;

	public native void unsubscribeHub(String topic) /*-{
		$wnd.gwtStreamHub.unsubscribe(topic);
	}-*/;

	public native void unsubscribeHub(JavaScriptObject topics) /*-{
		$wnd.gwtStreamHub.unsubscribe(topics);
	}-*/;

	public native void publish(String topic, String json) /*-{
		$wnd.gwtStreamHub.publish(topic, json);
	}-*/;
}
